<?php


namespace App\Zesow\Cache\Impl;

use Illuminate\Support\Facades\Cache;
use App\Services\Other\Interfaces\NavServiceInterface;

class NavCache
{

    public const KEY_NAME = 'navs';

    private $navService;

    public function __construct(NavServiceInterface $navService)
    {
        $this->navService = $navService;
    }

    public function get(string $platform)
    {

        if (Cache::has(self::KEY_NAME)) {
            return Cache::get(self::KEY_NAME);
        }
        $navs = $this->navService->all($platform);
        Cache::put(self::KEY_NAME, $navs);
        return $navs;


    }

    public function destroy(string $platform): void
    {
        Cache::forget($this->key($platform));
    }

    private function key(string $platform): string
    {
        return self::KEY_NAME . '-' . $platform;
    }

}
